#include<vector>
#include<algorithm>
using namespace std;

class Solution {
public:
    int smallestDifference(vector<int>& a, vector<int>& b) {
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        int i = 0, j = 0;
        int val = INT32_MAX;
        while (i < a.size() && j < b.size()) {
            int diff = a[i] - b[j];
            val = min(abs(diff), val);
            if (diff < 0)
                ++i;
            else
                ++j;
        }
        return val;
    }
};


int main() {
    Solution sol;
    vector<int>a = { 1, 3, 15, 11, 2 };
    vector<int>b = { 23, 127, 235, 19, 8 };
    sol.smallestDifference(a, b);
}